﻿using System.Threading.Tasks;

using NJ.Common.Extension;
using NJ.Dto.Log;
using NJ.Entity;

namespace NJ.Service.Log
{
    public class LogService : BaseService, ILogService
    {
        /// <summary>
        /// 添加操作日志
        /// </summary>
        /// <param name="logDto"></param>
        /// <returns></returns>
        public async Task<int> AddActionLogAsync(ActionLogDto logDto)
        {
            var logEntity = logDto.MapTo<ActionLogEntity>();
            Add(logEntity);
            var result = await SaveChangesAsync();
            return result;
        }

        /// <summary>
        /// 添加错误日志
        /// </summary>
        /// <param name="logDto"></param>
        /// <returns></returns>
        public async Task<int> AddErrorLogAsync(ErrorLogDto logDto)
        {
            var logEntity = logDto.MapTo<ErrorLogEntity>();
            Add(logEntity);
            var result = await SaveChangesAsync();
            return result;
        }
        /// <summary>
        /// 添加登录日志
        /// </summary>
        /// <param name="logDto"></param>
        /// <returns></returns>
        public async Task<int> AddLoginLogAsync(LoginLogDto logDto)
        {
            var logEntity = logDto.MapTo<LoginLogEntity>();
            Add(logEntity);
            var result = await SaveChangesAsync();
            return result;
        }
    }
}
